/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrameBanco.java
 *
 * Created on 04/10/2011, 14:25:26
 */
package br.com.GUI.cadastro;

import br.com.classes.Banco;
import br.com.dao.BancoDao;
import java.text.ParseException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

/**
 *
 * @author Kauane
 */
public class FrameBanco extends javax.swing.JFrame {

    int num = 0;
    int codoriginal;

    /** Creates new form FrameBanco */
    public FrameBanco() {
        initComponents();
        CarregarBanco();
    }

        public class LetraMaiuscula extends PlainDocument {  
     @Override  
     public void insertString(int offset, String str, AttributeSet attr)  
     throws BadLocationException {  
       super.insertString(offset, str.toUpperCase(), attr);  
     }    
}  
    
    public void CarregarBanco() {
        BancoDao bdao = new BancoDao();
        List<Banco> lista = bdao.ListarBanco();
        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaBanco.getModel();
        modelo.setRowCount(0);
        for (Banco b : lista) {
            modelo.addRow(new Object[]{b.getCod_banco(), b.getBanco(), b.getAgencia(), b.getConta()});
        }
        jTableConsultaBanco.setModel(modelo);
    }

    public void BuscarLimiteProximo() {
        num = num + 10;

        BancoDao bdao = new BancoDao();
        List<Banco> lista = bdao.BuscarLimite(num);

        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaBanco.getModel();
        modelo.setRowCount(0);

        for (Banco b : lista) {
            modelo.addRow(new Object[]{b.getCod_banco(), b.getBanco(), b.getAgencia(), b.getConta()});
        }

        jTableConsultaBanco.setModel(modelo);
        
         if(lista.size()<10){
    jButtonAvancar.setEnabled(false);
    }
    }

    public void BuscarLimiteAnterior() {
        num = num - 10;

        BancoDao bdao = new BancoDao();
        List<Banco> lista = bdao.BuscarLimite(num);

        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaBanco.getModel();
        modelo.setRowCount(0);

        for (Banco b : lista) {
            modelo.addRow(new Object[]{b.getCod_banco(), b.getBanco(), b.getAgencia(), b.getConta()});
        }
        jTableConsultaBanco.setModel(modelo);
           if(lista.size()<10){
    jButtonVoltar.setEnabled(false);
  }
           jButtonAvancar.setVisible(true);
    }

    public void CarregarBancoLetra() {
        String banco = jTextField11.getText();

        BancoDao bdao = new BancoDao();
        List<Banco> lista = bdao.ProcurarPorBancoLetra(banco);

        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaBanco.getModel();
        modelo.setRowCount(0);

        for (Banco b : lista) {
            modelo.addRow(new Object[]{b.getCod_banco(), b.getBanco(), b.getAgencia(), b.getConta()});

        }

        jTableConsultaBanco.setModel(modelo);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jTextFieldConta = new javax.swing.JTextField();
        jTextFieldBanco = new javax.swing.JTextField();
        jTextFieldAgencia = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableConsultaBanco = new javax.swing.JTable();
        jTextField11 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jButtonAvancar = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButtonEditar = new javax.swing.JButton();
        jButtonVoltar = new javax.swing.JButton();
        jButtonCadastrar = new javax.swing.JButton();
        jLabelBanco = new javax.swing.JLabel();
        jButtonLimparBanco = new javax.swing.JButton();

        setTitle("Cadastro de Bancos");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Cadastro de Bancos"));

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel11.setText("*Agência:");

        jTextFieldBanco.setDocument(new LetraMaiuscula());

        jTextFieldAgencia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldAgenciaActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("*Nome:");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel9.setText("*Conta:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)
                        .addGap(6, 6, 6)
                        .addComponent(jTextFieldBanco))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldConta)
                            .addComponent(jTextFieldAgencia))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldBanco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldAgencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldConta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(60, 60, 60))
        );

        jTableConsultaBanco.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Banco", "Agencia", "Conta"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableConsultaBanco.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTableConsultaBanco);
        jTableConsultaBanco.getColumnModel().getColumn(0).setMinWidth(110);
        jTableConsultaBanco.getColumnModel().getColumn(0).setPreferredWidth(110);
        jTableConsultaBanco.getColumnModel().getColumn(0).setMaxWidth(110);
        jTableConsultaBanco.getColumnModel().getColumn(1).setMinWidth(320);
        jTableConsultaBanco.getColumnModel().getColumn(1).setPreferredWidth(320);
        jTableConsultaBanco.getColumnModel().getColumn(1).setMaxWidth(320);
        jTableConsultaBanco.getColumnModel().getColumn(2).setMinWidth(150);
        jTableConsultaBanco.getColumnModel().getColumn(2).setPreferredWidth(150);
        jTableConsultaBanco.getColumnModel().getColumn(2).setMaxWidth(150);
        jTableConsultaBanco.getColumnModel().getColumn(3).setMinWidth(200);
        jTableConsultaBanco.getColumnModel().getColumn(3).setPreferredWidth(200);
        jTableConsultaBanco.getColumnModel().getColumn(3).setMaxWidth(200);

        jTextField11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField11ActionPerformed(evt);
            }
        });
        jTextField11.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField11KeyReleased(evt);
            }
        });

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/search[1].png"))); // NOI18N

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel12.setText("Pesquisa Banco:");

        jButtonAvancar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/next[2].png"))); // NOI18N
        jButtonAvancar.setBorder(null);
        jButtonAvancar.setContentAreaFilled(false);
        jButtonAvancar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/next[2]over.png"))); // NOI18N
        jButtonAvancar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAvancarActionPerformed(evt);
            }
        });

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/refresh.png"))); // NOI18N
        jButton8.setBorder(null);
        jButton8.setContentAreaFilled(false);
        jButton8.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/refresh[2]over.png"))); // NOI18N
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton3.setBackground(null);
        jButton3.setForeground(null);
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete[5].png"))); // NOI18N
        jButton3.setBorder(null);
        jButton3.setBorderPainted(false);
        jButton3.setContentAreaFilled(false);
        jButton3.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete[5]over.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil.png"))); // NOI18N
        jButtonEditar.setBorder(null);
        jButtonEditar.setContentAreaFilled(false);
        jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil[2]over.png"))); // NOI18N
        jButtonEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditarActionPerformed(evt);
            }
        });

        jButtonVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/back[2].png"))); // NOI18N
        jButtonVoltar.setBorder(null);
        jButtonVoltar.setContentAreaFilled(false);
        jButtonVoltar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/back[2]over.png"))); // NOI18N
        jButtonVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVoltarActionPerformed(evt);
            }
        });

        jButtonCadastrar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonCadastrar.setText("Cadastrar");
        jButtonCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCadastrarActionPerformed(evt);
            }
        });

        jLabelBanco.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabelBanco.setText("Banco");

        jButtonLimparBanco.setText("Limpar");
        jButtonLimparBanco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLimparBancoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(jLabelBanco)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 512, Short.MAX_VALUE)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel13))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButtonLimparBanco)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 315, Short.MAX_VALUE)
                        .addComponent(jButtonVoltar)
                        .addGap(10, 10, 10)
                        .addComponent(jButtonEditar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonAvancar)
                        .addGap(323, 323, 323))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 781, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelBanco)
                        .addGap(10, 10, 10))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(jTextField11))
                        .addGap(4, 4, 4))
                    .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.LEADING))
                .addGap(6, 6, 6)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonEditar)
                    .addComponent(jButton8)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonAvancar)
                    .addComponent(jButtonCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jButtonLimparBanco)
                        .addComponent(jButtonVoltar)))
                .addGap(16, 16, 16)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonAvancarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAvancarActionPerformed

        BuscarLimiteProximo();
        jButtonVoltar.setEnabled(true);
}//GEN-LAST:event_jButtonAvancarActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        CarregarBanco();
        jButtonAvancar.setEnabled(true);
}//GEN-LAST:event_jButton8ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

         if (jTableConsultaBanco.getSelectedRow() >= 0) {
        int linha = jTableConsultaBanco.getSelectedRow();
        Object[] OPTIONS = {"Sim", "Não"};
        String banco = jTableConsultaBanco.getValueAt(linha, 1).toString();

        BancoDao bdao = new BancoDao();
        Banco b = new Banco();
        b.setBanco(banco);

        try {
            int I = JOptionPane.showOptionDialog(null, "Tem certeza que deseja excluir o registro?", "Excluir", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, OPTIONS, OPTIONS[0]);
            if (I == JOptionPane.YES_OPTION) {

                bdao.DeletarBanco(b);
                CarregarBanco();
            }
        } catch (Exception e) {
            System.out.println("1 - " + e.getMessage());
        }}else {
           JOptionPane.showMessageDialog(null, "Por favor selecione um banco para ser excluido!");
       }   
}//GEN-LAST:event_jButton3ActionPerformed

    private void jButtonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEditarActionPerformed

if (jTableConsultaBanco.getSelectedRow() >= 0) { // Caso nao tenha sido selecionado nada na tabela da um aviso de erro
            if (jLabelBanco.getText() == "Banco") { //se for 1 estamos no cadastra se 2 no editar
                jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/removeicon.png")));
                jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/removeicon.png")));

               
        
        int k = jTableConsultaBanco.getSelectedRow();

        int cod_banco = (Integer) jTableConsultaBanco.getValueAt(k, 0);
        String banco = (String) jTableConsultaBanco.getValueAt(k, 1);
        String agencia = (String) jTableConsultaBanco.getValueAt(k, 2);
        String conta = (String) jTableConsultaBanco.getValueAt(k, 3);

        codoriginal = cod_banco;

        jLabelBanco.setText("Alterar Banco");
        jButtonCadastrar.setText("Alterar");
        jTextFieldBanco.setText(banco);
        jTextFieldAgencia.setText(agencia);
        jTextFieldConta.setText(conta);
         
            } else {
                
            jButtonCadastrar.setText("Cadastrar");                    
                    jLabelBanco.setText("Banco");
                    jTextFieldBanco.setText("");
                    jTextFieldAgencia.setText("");
                    jTextFieldConta.setText("");
            jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil.png")));
                jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil[2]over.png")));
            }
        } else {
            JOptionPane.showMessageDialog(this, "Favor selecionar o Banco para ser alterado!");
        }
    
}//GEN-LAST:event_jButtonEditarActionPerformed

    private void jButtonVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVoltarActionPerformed

        BuscarLimiteAnterior();
        jButtonAvancar.setEnabled(true);
         
}//GEN-LAST:event_jButtonVoltarActionPerformed

    private void jTextFieldAgenciaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldAgenciaActionPerformed
         
    }//GEN-LAST:event_jTextFieldAgenciaActionPerformed

    private void jButtonCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCadastrarActionPerformed

        if (jTextFieldBanco.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Favor preencher os campos!");
        } else {

            if (jLabelBanco.getText().equals("Banco")) {
                try {
                    Banco b = new Banco();
                    BancoDao bdao = new BancoDao();
                    int codban = bdao.UltimoCodBanco();

                    DefaultTableModel modelo = (DefaultTableModel) jTableConsultaBanco.getModel();

                    b.setBanco(jTextFieldBanco.getText());
                    b.setAgencia(jTextFieldAgencia.getText());
                    b.setConta(jTextFieldConta.getText());

                    bdao.CadastrarBanco(b);
                    //BuscarLimiteProximo();
                    modelo.addRow(new Object[]{codban, b.getBanco(), b.getAgencia(), b.getConta()});
                    jTableConsultaBanco.setModel(modelo);

                    JOptionPane.showMessageDialog(this, "Cadastrado com sucesso");
                    jTextFieldBanco.setText("");
                    jTextFieldAgencia.setText("");
                    jTextFieldConta.setText("");

                } catch (Exception e) {
                    System.out.println("1 - " + e.getMessage());
                }
            } else {
                try {
                    
                    Object[] OPTIONS = {"Sim", "Não"};
                    int I = JOptionPane.showOptionDialog(null, "Tem certeza que deseja alterar o registro?", "Alterar", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, OPTIONS, OPTIONS[0]);
                    if (I == JOptionPane.YES_OPTION) {
                    
                    Banco b = new Banco();
                    b.setCod_banco(codoriginal);
                    b.setBanco(jTextFieldBanco.getText());
                    b.setAgencia(jTextFieldAgencia.getText());
                    b.setConta(jTextFieldConta.getText());

                    DefaultTableModel modelo = (DefaultTableModel) jTableConsultaBanco.getModel();

                    BancoDao bdao = new BancoDao();
                    bdao.AlterarBanco(b);
                    }
                    CarregarBanco();
                    jButtonCadastrar.setText("Cadastrar");                    
                    jLabelBanco.setText("Banco");
                    jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil[2]over.png")));
                    jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil.png")));
                    jTextFieldBanco.setText("");
                    jTextFieldAgencia.setText("");
                    jTextFieldConta.setText("");
                } catch (Exception e) {
                    System.out.println("1 - " + e.getMessage());
                }
            }
        }
    }//GEN-LAST:event_jButtonCadastrarActionPerformed

    private void jTextField11KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField11KeyReleased

        CarregarBancoLetra();
         
    }//GEN-LAST:event_jTextField11KeyReleased

    private void jTextField11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField11ActionPerformed
         
    }//GEN-LAST:event_jTextField11ActionPerformed

    private void jButtonLimparBancoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLimparBancoActionPerformed
         
                            jTextFieldBanco.setText("");
                    jTextFieldAgencia.setText("");
                    jTextFieldConta.setText("");
    }//GEN-LAST:event_jButtonLimparBancoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FrameBanco().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButtonAvancar;
    private javax.swing.JButton jButtonCadastrar;
    private javax.swing.JButton jButtonEditar;
    private javax.swing.JButton jButtonLimparBanco;
    private javax.swing.JButton jButtonVoltar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelBanco;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableConsultaBanco;
    private javax.swing.JTextField jTextField11;
    private javax.swing.JTextField jTextFieldAgencia;
    private javax.swing.JTextField jTextFieldBanco;
    private javax.swing.JTextField jTextFieldConta;
    // End of variables declaration//GEN-END:variables
}
